<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\VaccineType;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class VaccineTypeController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new VaccineType(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('icon')->image('http://static.i.wedoctors.com.cn/', 100, 100);
            $grid->column('type')->using([1=>'免规',2=>'非免规']);
            $grid->column('crowd')->using([1=>'儿童',2=>'成人']);


            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new VaccineType(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('disease');
            $show->field('adverse_reactions');
            $show->field('contraindications');
            $show->field('disease_harm');
            $show->field('deal_flow');
            $show->field('inoculability');
            $show->field('type');
            $show->field('crowd');
            $show->field('icon');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new VaccineType(), function (Form $form) {
            $form->text('name');
            $form->image('icon')
                ->uniqueName()
                ->autoUpload()
                ->accept('jpg,png,gif,jpeg', 'image/*')
                ->maxSize(500)->disk('oss');
            $form->select('type')->options(\App\Models\VaccineType::$typeEnum)->required();
            $form->select('crowd')->options(\App\Models\VaccineType::$crowdEnum)->required();
            $form->text('disease');
            $form->text('adverse_reactions');
            $form->text('contraindications');
            $form->text('disease_harm');
            $form->text('deal_flow');
            $form->text('inoculability');
        });
    }
}
